/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.dao.jpa;

import com.supinfo.youfood.dao.RestaurantDao;
import com.supinfo.youfood.entity.Menu;
import com.supinfo.youfood.entity.Restaurant;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Michael
 * 
 */
@Stateless
public class JpaRestaurantDao implements RestaurantDao{
    
    @PersistenceContext
    EntityManager em;

    @Override
    public Restaurant findRestoById(Long id) {
        return em.find(Restaurant.class, id);
    }
    
    @Override
    public List<Restaurant> getAllResto() {
        String query = "SELECT r "+
                        "FROM Restaurant r";
        Query result = em.createQuery(query);
        return (List<Restaurant>)result.getResultList();
    }

    @Override
    public void refreshResto(Restaurant resto) {
        em.merge(resto);
    }

    @Override
    public Restaurant addResto(Restaurant resto) {
        em.persist(resto);
        return resto;
    }
    
}
